package 力扣日常刷题.木22二月.第02天207;

/**
 * @author 帅小伙
 * @date 2022/2/7
 * @description
 */
public class Demo30贪心增减字符串匹配 {

    public static void main(String[] args) {
        diStringMatch("IDID");
    }

    public static int[] diStringMatch(String s) {
        int d = s.length(), i = 0;
        int[] ans = new int[s.length() + 1];
        for (int j = 0; j < s.length(); j++) {
            if(s.charAt(j) == 'D')ans[j] = d--;
            else ans[j] = i ++;
        }
        ans[s.length()] = d;
        return ans;
    }
}
